package com.example.uCenter.utils;

import org.springframework.util.DigestUtils;

/**
 * 密码加盐工具类
 */
public class SaltUtil {

    public static String AddSalt(String salt,String password){

        // 拼接
        String passwords = salt + password + salt;
        // 基于spring框架中的DigestUtils工具类进行密码加密
        String hashedPwd1 = DigestUtils.md5DigestAsHex((passwords).getBytes());
        char[] cs = new char[48];
        for (int i = 0; i < 48; i += 3) {
            cs[i] = hashedPwd1.charAt(i / 3 * 2);
            cs[i + 1] = salt.charAt(i / 3);
            cs[i + 2] = hashedPwd1.charAt(i / 3 * 2 + 1);
        }
        return new String(cs);
    }
}
